package com.unity3d.player;

import android.util.*;
import android.widget.*;
import android.content.*;
import android.app.*;
import java.security.*;
import java.util.*;
import android.content.pm.*;
import java.io.*;
import org.xmlpull.v1.*;
import java.util.concurrent.*;
import android.telephony.*;
import android.content.res.*;
import android.view.*;
import java.util.concurrent.atomic.*;
import android.os.*;

public class UnityPlayer extends FrameLayout implements com.unity3d.player.d
{
    public static Activity currentActivity;
    private static boolean n;
    c a;
    h b;
    private boolean c;
    private boolean d;
    private k e;
    private final ConcurrentLinkedQueue f;
    private BroadcastReceiver g;
    private boolean h;
    private a i;
    private TelephonyManager j;
    private i k;
    private ContextWrapper l;
    private SurfaceView m;
    private boolean o;
    private Bundle p;
    private m q;
    private boolean r;
    private ProgressBar s;
    private Runnable t;
    private Runnable u;
    private com.unity3d.player.b v;

    static {
        new j().a();
        UnityPlayer.n = false;
        UnityPlayer.n = loadLibraryStatic("main");
    }

    public UnityPlayer(final ContextWrapper l) {
        super((Context)l);
        this.c = false;
        this.d = true;
        this.e = new k();
        this.f = new ConcurrentLinkedQueue();
        this.g = null;
        this.a = new c((byte)0);
        this.h = false;
        this.i = new a((byte)0);
        this.p = new Bundle();
        this.r = false;
        this.b = null;
        this.s = null;
        this.t = new Runnable() {
            @Override
            public final void run() {
                final int l = UnityPlayer.this.nativeActivityIndicatorStyle();
                if (l >= 0) {
                    if (UnityPlayer.this.s == null) {
                        final UnityPlayer a;
                        a.s = new ProgressBar((Context)(a = UnityPlayer.this).l, (AttributeSet)null, (new int[] { 16842874, 16843401, 16842873, 16843400 })[l]);
                        UnityPlayer.this.s.setIndeterminate(true);
                        UnityPlayer.this.s.setLayoutParams((ViewGroup.LayoutParams)new FrameLayout.LayoutParams(-2, -2, 51));
                        final UnityPlayer a2 = UnityPlayer.this;
                        a2.addView((View)a2.s);
                    }
                    UnityPlayer.this.s.setVisibility(0);
                    final UnityPlayer a3 = UnityPlayer.this;
                    a3.bringChildToFront((View)a3.s);
                }
            }
        };
        this.u = new Runnable() {
            @Override
            public final void run() {
                if (UnityPlayer.this.s != null) {
                    UnityPlayer.this.s.setVisibility(8);
                    final UnityPlayer a = UnityPlayer.this;
                    a.removeView((View)a.s);
                    UnityPlayer.this.s = null;
                }
            }
        };
        this.v = new com.unity3d.player.b(this);
        if (l instanceof Activity) {
            UnityPlayer.currentActivity = (Activity)l;
        }
        a(UnityPlayer.currentActivity);
        this.l = l;
        this.b();
        if (UnityPlayer.currentActivity != null && this.p.getBoolean("showSplash")) {
            this.k = new i((View)this, com.unity3d.player.i.a.a()[this.getSplashMode()]);
        }
        if (com.unity3d.player.g.c) {
            if (UnityPlayer.currentActivity != null) {
                com.unity3d.player.g.d.a(UnityPlayer.currentActivity, new Runnable() {
                    @Override
                    public final void run() {
                        UnityPlayer.this.a(new Runnable() {
                            @Override
                            public final void run() {
                                UnityPlayer.this.e.d();
                                UnityPlayer.this.f();
                            }
                        });
                    }
                });
            }
            else {
                this.e.d();
            }
        }
        a(this.l.getApplicationInfo());
        if (!com.unity3d.player.k.c()) {
            final AlertDialog create = new AlertDialog.Builder((Context)this.l).setTitle((CharSequence)"Failure to initialize!").setPositiveButton((CharSequence)"OK", (DialogInterface.OnClickListener)new DialogInterface.OnClickListener() {
                public final void onClick(final DialogInterface dialogInterface, final int n) {
                    UnityPlayer.this.c();
                }
            }).setMessage((CharSequence)"Your hardware does not support this application, sorry!").create();
            create.setCancelable(false);
            create.show();
            return;
        }
        this.initJni((Context)l);
        this.nativeFile(this.l.getPackageCodePath());
        this.h();
        (this.m = this.a()).setZOrderOnTop(true);
        this.addView((View)this.m);
        this.o = false;
        final Activity currentActivity = UnityPlayer.currentActivity;
        if (currentActivity != null) {
            this.v.a(currentActivity.getIntent());
        }
        this.nativeInitWWW(WWW.class);
        this.nativeInitWebRequest(UnityWebRequest.class);
        this.i();
        this.j = (TelephonyManager)this.l.getSystemService("phone");
        this.a.start();
    }

    public static void UnitySendMessage(final String s, final String s2, final String s3) {
        if (!k.c()) {
            final StringBuilder sb = new StringBuilder("Native libraries not loaded - dropping message for ");
            sb.append(s);
            sb.append(".");
            sb.append(s2);
            e.Log(5, sb.toString());
            return;
        }
        nativeUnitySendMessage(s, s2, s3);
    }

    private SurfaceView a() {
        final SurfaceView surfaceView = new SurfaceView((Context)this.l);
        surfaceView.getHolder().setFormat(2);
        surfaceView.getHolder().addCallback((SurfaceHolder.Callback)new SurfaceHolder.Callback() {
            public final void surfaceChanged(final SurfaceHolder surfaceHolder, final int n, final int n2, final int n3) {
                UnityPlayer.a(UnityPlayer.this, surfaceHolder.getSurface());
            }

            public final void surfaceCreated(final SurfaceHolder surfaceHolder) {
                UnityPlayer.a(UnityPlayer.this, surfaceHolder.getSurface());
            }

            public final void surfaceDestroyed(final SurfaceHolder surfaceHolder) {
                UnityPlayer.a(UnityPlayer.this, (Surface)null);
            }
        });
        surfaceView.setFocusable(true);
        surfaceView.setFocusableInTouchMode(true);
        return surfaceView;
    }

    private static String a(final String s) {
        final int n = 0;
        while (true) {
            try {
                final MessageDigest instance = MessageDigest.getInstance("MD5");
                final FileInputStream fileInputStream = new FileInputStream(s);
                final long length = new File(s).length();
                fileInputStream.skip(length - Math.min(length, 65558L));
                final byte[] array = new byte[1024];
                for (int i = 0; i != -1; i = fileInputStream.read(array)) {
                    instance.update(array, 0, i);
                }
                try {
                    byte[] digest = instance.digest();
                    if (digest == null) {
                        return null;
                    }
                    final StringBuffer sb = new StringBuffer();
                    for (int j = n; j < digest.length; ++j) {
                        sb.append(Integer.toString((digest[j] & 0xFF) + 256, 16).substring(1));
                    }
                    return sb.toString();
                    digest = null;
                }
                catch (IOException ex) {}
            }
            catch (FileNotFoundException ex2) {}
            catch (IOException ex3) {}
            catch (NoSuchAlgorithmException ex4) {}
            continue;
        }
    }

    private void a(final int n, final Surface surface) {
        if (this.c) {
            return;
        }
        this.b(0, surface);
    }

    private static void a(final Activity activity) {
        if (activity != null && activity.getIntent().getBooleanExtra("android.intent.extra.VR_LAUNCH", false) && activity.getWindow() != null) {
            final View decorView = activity.getWindow().getDecorView();
            if (decorView != null) {
                decorView.setSystemUiVisibility(7);
            }
        }
    }

    private static void a(final ApplicationInfo applicationInfo) {
        if (UnityPlayer.n && NativeLoader.load(applicationInfo.nativeLibraryDir)) {
            k.a();
        }
    }

    private void a(final View view, final View view2) {
        if (view != null) {
            final ViewParent parent = view.getParent();
            if (!(parent instanceof UnityPlayer) || (UnityPlayer)parent != this) {
                if (parent instanceof ViewGroup) {
                    ((ViewGroup)parent).removeView(view);
                }
                this.addView(view);
            }
        }
        if (view2 != null && view2.getParent() == this) {
            this.removeView(view2);
        }
    }

    private void a(final d d) {
        if (this.isFinishing()) {
            return;
        }
        this.b(d);
    }

    static /* synthetic */ void a(final UnityPlayer unityPlayer, final Surface surface) {
        unityPlayer.a(0, surface);
    }

    private static String[] a(final Context context) {
        final String packageName = context.getPackageName();
        final Vector<String> vector = new Vector<String>();
        try {
            final int versionCode = context.getPackageManager().getPackageInfo(packageName, 0).versionCode;
            if (Environment.getExternalStorageState().equals("mounted")) {
                final File externalStorageDirectory = Environment.getExternalStorageDirectory();
                final StringBuilder sb = new StringBuilder();
                sb.append(externalStorageDirectory.toString());
                sb.append("/Android/obb/");
                sb.append(packageName);
                final File file = new File(sb.toString());
                if (file.exists()) {
                    if (versionCode > 0) {
                        final StringBuilder sb2 = new StringBuilder();
                        sb2.append(file);
                        sb2.append(File.separator);
                        sb2.append("main.");
                        sb2.append(versionCode);
                        sb2.append(".");
                        sb2.append(packageName);
                        sb2.append(".obb");
                        final String string = sb2.toString();
                        if (new File(string).isFile()) {
                            vector.add(string);
                        }
                    }
                    if (versionCode > 0) {
                        final StringBuilder sb3 = new StringBuilder();
                        sb3.append(file);
                        sb3.append(File.separator);
                        sb3.append("patch.");
                        sb3.append(versionCode);
                        sb3.append(".");
                        sb3.append(packageName);
                        sb3.append(".obb");
                        final String string2 = sb3.toString();
                        if (new File(string2).isFile()) {
                            vector.add(string2);
                        }
                    }
                }
            }
            final String[] array = new String[vector.size()];
            vector.toArray(array);
            return array;
        }
        catch (PackageManager.NameNotFoundException ex) {
            return new String[0];
        }
    }

    private void b() {
        File file;
        InputStream open;
        XmlPullParserFactory instance;
        XmlPullParser pullParser;
        int n = 0;
        String s = null;
        String attributeValue = null;
        String name;
        int n2 = 0;
        String s2;
        StringBuilder sb;
        Label_0109_Outer:Label_0149_Outer:Label_0295_Outer:
        while (true) {
            Label_0295:
            while (true) {
                Label_0373: {
                    while (true) {
                        Label_0360: {
                            Label_0355:
                            while (true) {
                                Label_0348: {
                                    try {
                                        file = new File(this.l.getPackageCodePath(), "assets/bin/Data/settings.xml");
                                        if (file.exists()) {
                                            open = new FileInputStream(file);
                                        }
                                        else {
                                            open = this.l.getAssets().open("bin/Data/settings.xml");
                                        }
                                        instance = XmlPullParserFactory.newInstance();
                                        instance.setNamespaceAware(true);
                                        pullParser = instance.newPullParser();
                                        pullParser.setInput(open, (String)null);
                                        n = pullParser.getEventType();
                                        attributeValue = (s = null);
                                        // iftrue(Label_0263:, !s.equalsIgnoreCase("bool"))
                                        // iftrue(Label_0295:, attributeValue == null)
                                        // iftrue(Label_0202:, !s.equalsIgnoreCase("integer"))
                                        // iftrue(Label_0295:, n != 4)
                                        // iftrue(Label_0231:, !s.equalsIgnoreCase("string"))
                                        while (true) {
                                            while (true) {
                                                if (n == 1) {
                                                    return;
                                                }
                                                if (n != 2) {
                                                    break Label_0360;
                                                }
                                                name = pullParser.getName();
                                                n2 = 0;
                                                if (n2 >= pullParser.getAttributeCount()) {
                                                    break Label_0355;
                                                }
                                                if (pullParser.getAttributeName(n2).equalsIgnoreCase("name")) {
                                                    attributeValue = pullParser.getAttributeValue(n2);
                                                }
                                                break Label_0348;
                                                Label_0231: {
                                                    this.p.putBoolean(attributeValue, Boolean.parseBoolean(pullParser.getText()));
                                                }
                                                break Label_0373;
                                                Block_10: {
                                                    while (true) {
                                                        s2 = attributeValue;
                                                        name = s;
                                                        break Block_10;
                                                        s2 = attributeValue;
                                                        name = s;
                                                        continue Label_0149_Outer;
                                                    }
                                                    this.p.putString(attributeValue, pullParser.getText());
                                                    break Label_0373;
                                                }
                                                this.p.putInt(attributeValue, Integer.parseInt(pullParser.getText()));
                                                break Label_0373;
                                                n = pullParser.next();
                                                attributeValue = s2;
                                                s = name;
                                                continue Label_0109_Outer;
                                            }
                                            Label_0202: {
                                                continue Label_0295_Outer;
                                            }
                                        }
                                        while (true) {
                                            this.p.putFloat(attributeValue, Float.parseFloat(pullParser.getText()));
                                            break Label_0373;
                                            Label_0263: {
                                                continue;
                                            }
                                        }
                                    }
                                    // iftrue(Label_0373:, !s.equalsIgnoreCase("float"))
                                    catch (Exception ex) {
                                        sb = new StringBuilder("Unable to locate player settings. ");
                                        sb.append(ex.getLocalizedMessage());
                                        com.unity3d.player.e.Log(6, sb.toString());
                                        this.c();
                                        return;
                                    }
                                }
                                ++n2;
                                continue Label_0149_Outer;
                            }
                            s2 = attributeValue;
                            continue Label_0295;
                        }
                        if (n == 3) {
                            name = null;
                            s2 = attributeValue;
                            continue Label_0295;
                        }
                        continue Label_0295_Outer;
                    }
                }
                s2 = null;
                name = s;
                continue Label_0295;
            }
        }
    }

    private void b(final Runnable runnable) {
        if (!com.unity3d.player.k.c()) {
            return;
        }
        if (Thread.currentThread() == this.a) {
            runnable.run();
            return;
        }
        this.f.add(runnable);
    }

    private boolean b(final int n, final Surface surface) {
        if (!com.unity3d.player.k.c()) {
            return false;
        }
        this.nativeRecreateGfxState(n, surface);
        return true;
    }

    private void c() {
        final ContextWrapper l = this.l;
        if (l instanceof Activity && !((Activity)l).isFinishing()) {
            ((Activity)this.l).finish();
        }
    }

    private void d() {
        this.reportSoftInputStr(null, 1, true);
        if (!this.e.g()) {
            return;
        }
        while (true) {
            Label_0109: {
                if (!com.unity3d.player.k.c()) {
                    break Label_0109;
                }
                final Semaphore semaphore = new Semaphore(0);
                Runnable runnable;
                if (this.isFinishing()) {
                    runnable = new Runnable() {
                        @Override
                        public final void run() {
                            UnityPlayer.this.e();
                            semaphore.release();
                        }
                    };
                }
                else {
                    runnable = new Runnable() {
                        @Override
                        public final void run() {
                            if (UnityPlayer.this.nativePause()) {
                                UnityPlayer.this.o = true;
                                UnityPlayer.this.e();
                                semaphore.release(2);
                                return;
                            }
                            semaphore.release();
                        }
                    };
                }
                this.b(runnable);
                try {
                    if (!semaphore.tryAcquire(4L, TimeUnit.SECONDS)) {
                        com.unity3d.player.e.Log(5, "Timeout while trying to pause the Unity Engine.");
                    }
                    while (true) {
                        if (semaphore.drainPermits() > 0) {
                            this.quit();
                        }
                        this.e.c(false);
                        this.e.b(true);
                        if (this.h) {
                            this.j.listen((PhoneStateListener)this.i, 0);
                        }
                        this.a.c();
                        return;
                        com.unity3d.player.e.Log(5, "UI thread got interrupted while trying to pause the Unity Engine.");
                        continue;
                    }
                }
                catch (InterruptedException ex) {}
            }
            continue;
        }
    }

    private void e() {
        this.nativeDone();
    }

    private void f() {
        if (!this.e.f()) {
            return;
        }
        this.e.c(true);
        if (com.unity3d.player.k.c()) {
            this.h();
        }
        this.b(new Runnable() {
            @Override
            public final void run() {
                UnityPlayer.this.nativeResume();
            }
        });
        this.a.b();
    }

    private static void g() {
        if (!k.c()) {
            return;
        }
        if (NativeLoader.unload()) {
            k.b();
            return;
        }
        throw new UnsatisfiedLinkError("Unable to unload libraries from libmain.so");
    }

    private void h() {
        if (!this.p.getBoolean("useObb")) {
            return;
        }
        final String[] a = a((Context)this.l);
        for (int length = a.length, i = 0; i < length; ++i) {
            final String s = a[i];
            final String a2 = a(s);
            if (this.p.getBoolean(a2)) {
                this.nativeFile(s);
            }
            this.p.remove(a2);
        }
    }

    private void i() {
        final ContextWrapper l = this.l;
        if (l instanceof Activity) {
            ((Activity)l).getWindow().setFlags(1024, 1024);
        }
    }

    private final native void initJni(final Context p0);

    protected static boolean loadLibraryStatic(final String s) {
        try {
            System.loadLibrary(s);
            return true;
        }
        catch (Exception ex) {
            new StringBuilder("Unknown error ").append(ex);
        }
        catch (UnsatisfiedLinkError unsatisfiedLinkError) {
            goto Label_0035;
        }
    }

    private final native int nativeActivityIndicatorStyle();

    private final native void nativeDone();

    private final native void nativeFile(final String p0);

    private final native void nativeFocusChanged(final boolean p0);

    private final native void nativeInitWWW(final Class p0);

    private final native void nativeInitWebRequest(final Class p0);

    private final native boolean nativeInjectEvent(final InputEvent p0);

    private final native void nativeLowMemory();

    private final native void nativeMuteMasterAudio(final boolean p0);

    private final native boolean nativePause();

    private final native void nativeRecreateGfxState(final int p0, final Surface p1);

    private final native boolean nativeRender();

    private final native void nativeResume();

    private final native void nativeSetInputCanceled(final boolean p0);

    private final native void nativeSetInputString(final String p0);

    private final native void nativeSoftInputClosed();

    private static native void nativeUnitySendMessage(final String p0, final String p1, final String p2);

    static /* synthetic */ void o(final UnityPlayer unityPlayer) {
        unityPlayer.nativeSetInputCanceled(true);
    }

    final void a(final Runnable runnable) {
        final ContextWrapper l = this.l;
        if (l instanceof Activity) {
            ((Activity)l).runOnUiThread(runnable);
            return;
        }
        com.unity3d.player.e.Log(5, "Not running Unity from an Activity; ignored...");
    }

    protected void addPhoneCallListener() {
        this.h = true;
        this.j.listen((PhoneStateListener)this.i, 32);
    }

    public boolean addViewToPlayer(final View view, final boolean b) {
        Object m;
        if (b) {
            m = this.m;
        }
        else {
            m = null;
        }
        this.a(view, (View)m);
        final ViewParent parent = view.getParent();
        final boolean b2 = true;
        final boolean b3 = parent == this;
        final boolean b4 = b && this.m.getParent() == null;
        final boolean b5 = this.m.getParent() == this;
        boolean b6 = false;
        Label_0111: {
            if (b3) {
                b6 = b2;
                if (b4) {
                    break Label_0111;
                }
                if (b5) {
                    b6 = b2;
                    break Label_0111;
                }
            }
            b6 = false;
        }
        if (!b6) {
            if (!b3) {
                com.unity3d.player.e.Log(6, "addViewToPlayer: Failure adding view to hierarchy");
            }
            if (!b4 && !b5) {
                com.unity3d.player.e.Log(6, "addViewToPlayer: Failure removing old view from hierarchy");
            }
        }
        return b6;
    }

    public void configurationChanged(final Configuration configuration) {
        final SurfaceView m = this.m;
        if (m instanceof SurfaceView) {
            m.getHolder().setSizeFromLayout();
        }
        final m q = this.q;
        if (q != null) {
            q.updateVideoLayout();
        }
    }

    protected void disableLogger() {
        com.unity3d.player.e.a = true;
    }

    public boolean displayChanged(final int n, final Surface surface) {
        if (n == 0) {
            this.c = (surface != null);
            this.a(new Runnable() {
                @Override
                public final void run() {
                    if (UnityPlayer.this.c) {
                        final UnityPlayer a = UnityPlayer.this;
                        a.removeView((View)a.m);
                        return;
                    }
                    final UnityPlayer a2 = UnityPlayer.this;
                    a2.addView((View)a2.m);
                }
            });
        }
        return this.b(n, surface);
    }

    protected void executeGLThreadJobs() {
        while (true) {
            final Runnable runnable = this.f.poll();
            if (runnable == null) {
                break;
            }
            runnable.run();
        }
    }

    public Bundle getSettings() {
        return this.p;
    }

    protected int getSplashMode() {
        return this.p.getInt("splash_mode", 0);
    }

    public View getView() {
        return (View)this;
    }

    protected void hideSoftInput() {
        final Runnable runnable = new Runnable() {
            @Override
            public final void run() {
                if (UnityPlayer.this.b != null) {
                    UnityPlayer.this.b.dismiss();
                    UnityPlayer.this.b = null;
                }
            }
        };
        if (com.unity3d.player.g.b) {
            this.a((d)new d() {
                @Override
                public final void a() {
                    UnityPlayer.this.a(runnable);
                }
            });
            return;
        }
        this.a(runnable);
    }

    public void init(final int n, final boolean b) {
    }

    public boolean injectEvent(final InputEvent inputEvent) {
        return this.nativeInjectEvent(inputEvent);
    }

    protected boolean isFinishing() {
        if (!this.o) {
            final ContextWrapper l = this.l;
            return this.o = (l instanceof Activity && ((Activity)l).isFinishing());
        }
        return true;
    }

    protected void kill() {
        Process.killProcess(Process.myPid());
    }

    protected long loadGoogleVR(final boolean b, final boolean b2, final boolean b3) {
        if (!this.v.a(UnityPlayer.currentActivity, (Context)this.l, this.a())) {
            com.unity3d.player.e.Log(6, "Unable to initialize Google VR subsystem.");
            return 0L;
        }
        return this.v.a(b, b2, b3, new Runnable() {
            @Override
            public final void run() {
                UnityPlayer.this.c();
            }
        });
    }

    protected boolean loadLibrary(final String s) {
        return loadLibraryStatic(s);
    }

    public void lowMemory() {
        this.b(new Runnable() {
            @Override
            public final void run() {
                UnityPlayer.this.nativeLowMemory();
            }
        });
    }

    public boolean onGenericMotionEvent(final MotionEvent motionEvent) {
        return this.injectEvent((InputEvent)motionEvent);
    }

    public boolean onKeyDown(final int n, final KeyEvent keyEvent) {
        return this.injectEvent((InputEvent)keyEvent);
    }

    public boolean onKeyLongPress(final int n, final KeyEvent keyEvent) {
        return this.injectEvent((InputEvent)keyEvent);
    }

    public boolean onKeyMultiple(final int n, final int n2, final KeyEvent keyEvent) {
        return this.injectEvent((InputEvent)keyEvent);
    }

    public boolean onKeyUp(final int n, final KeyEvent keyEvent) {
        return this.injectEvent((InputEvent)keyEvent);
    }

    public boolean onTouchEvent(final MotionEvent motionEvent) {
        return this.injectEvent((InputEvent)motionEvent);
    }

    public void pause() {
        final m q = this.q;
        if (q != null) {
            if (!(this.r = q.a())) {
                this.q.pause();
            }
            return;
        }
        this.v.b();
        this.d();
    }

    public void quit() {
        this.v.a();
        this.o = true;
        if (!this.e.e()) {
            this.pause();
        }
        this.unloadGoogleVR();
        this.a.a();
        while (true) {
            try {
                this.a.join(4000L);
                while (true) {
                    final BroadcastReceiver g = this.g;
                    if (g != null) {
                        this.l.unregisterReceiver(g);
                    }
                    this.g = null;
                    if (com.unity3d.player.k.c()) {
                        this.removeAllViews();
                    }
                    this.kill();
                    g();
                    return;
                    this.a.interrupt();
                    continue;
                }
            }
            catch (InterruptedException ex) {}
            continue;
        }
    }

    public void removeViewFromPlayer(final View view) {
        this.a((View)this.m, view);
        final ViewParent parent = view.getParent();
        boolean b = true;
        final boolean b2 = parent == null;
        final boolean b3 = this.m.getParent() == this;
        if (!b2 || !b3) {
            b = false;
        }
        if (!b) {
            if (!b2) {
                com.unity3d.player.e.Log(6, "removeViewFromPlayer: Failure removing view from hierarchy");
            }
            if (!b3) {
                com.unity3d.player.e.Log(6, "removeVireFromPlayer: Failure agging old view to hierarchy");
            }
        }
    }

    public void reportError(final String s, final String s2) {
        final StringBuilder sb = new StringBuilder();
        sb.append(s);
        sb.append(": ");
        sb.append(s2);
        com.unity3d.player.e.Log(6, sb.toString());
    }

    protected void reportSoftInputStr(final String s, final int n, final boolean b) {
        if (n == 1) {
            this.hideSoftInput();
        }
        this.a((d)new d() {
            @Override
            public final void a() {
                if (b) {
                    UnityPlayer.o(UnityPlayer.this);
                }
                else {
                    final String b = s;
                    if (b != null) {
                        UnityPlayer.this.nativeSetInputString(b);
                    }
                }
                if (n == 1) {
                    UnityPlayer.this.nativeSoftInputClosed();
                }
            }
        });
    }

    public void resume() {
        this.e.b(false);
        final m q = this.q;
        if (q != null) {
            if (!this.r) {
                q.start();
            }
            return;
        }
        this.f();
        this.v.c();
    }

    protected void setGoogleVREnabled(final boolean b) {
        this.v.a(b);
    }

    protected void setSoftInputStr(final String s) {
        this.a(new Runnable() {
            @Override
            public final void run() {
                if (UnityPlayer.this.b != null && s != null) {
                    UnityPlayer.this.b.a(s);
                }
            }
        });
    }

    protected void showSoftInput(final String s, final int n, final boolean b, final boolean b2, final boolean b3, final boolean b4, final String s2) {
        this.a(new Runnable() {
            @Override
            public final void run() {
                final UnityPlayer i = UnityPlayer.this;
                i.b = new h((Context)i.l, UnityPlayer.this, s, n, b, b2, b3, s2);
                UnityPlayer.this.b.show();
            }
        });
    }

    protected boolean showVideoPlayer(final String s, int value, final int n, final int n2, final boolean b, final int n3, final int n4) {
        final boolean b2 = false;
        final Semaphore semaphore = new Semaphore(0);
        final AtomicInteger atomicInteger = new AtomicInteger(-1);
        this.a(new Runnable() {
            @Override
            public final void run() {
                if (UnityPlayer.this.q != null) {
                    com.unity3d.player.e.Log(5, "Video already playing");
                    atomicInteger.set(2);
                    semaphore.release();
                    return;
                }
                final UnityPlayer j;
                j.q = new m((Context)(j = UnityPlayer.this).l, s, value, n, n2, b, n3, n4, (m.a)new m.a() {
                    @Override
                    public final void a(final int n) {
                        atomicInteger.set(n);
                        if (n == 3) {
                            if (UnityPlayer.this.m.getParent() == null) {
                                UnityPlayer.this.addView((View)UnityPlayer.this.m);
                            }
                            if (UnityPlayer.this.q != null) {
                                UnityPlayer.this.q.destroyPlayer();
                                UnityPlayer.this.removeView((View)UnityPlayer.this.q);
                                UnityPlayer.this.q = null;
                            }
                            UnityPlayer.this.resume();
                        }
                        if (n != 0) {
                            semaphore.release();
                        }
                    }
                });
                final UnityPlayer i = UnityPlayer.this;
                i.addView((View)i.q);
            }
        });
        while (true) {
            try {
                semaphore.acquire();
                value = atomicInteger.get();
                boolean b3 = b2;
                if (value != 2) {
                    b3 = true;
                }
                Runnable runnable;
                if (b3) {
                    if (this.q == null) {
                        return b3;
                    }
                    runnable = new Runnable() {
                        @Override
                        public final void run() {
                            if (UnityPlayer.this.q != null) {
                                UnityPlayer.this.d();
                                UnityPlayer.this.q.requestFocus();
                                final UnityPlayer a = UnityPlayer.this;
                                a.removeView((View)a.m);
                            }
                        }
                    };
                }
                else {
                    if (this.q == null) {
                        return b3;
                    }
                    runnable = new Runnable() {
                        @Override
                        public final void run() {
                            if (UnityPlayer.this.m.getParent() == null) {
                                final UnityPlayer a = UnityPlayer.this;
                                a.addView((View)a.m);
                            }
                            if (UnityPlayer.this.q != null) {
                                UnityPlayer.this.q.destroyPlayer();
                                final UnityPlayer a2 = UnityPlayer.this;
                                a2.removeView((View)a2.q);
                                UnityPlayer.this.q = null;
                            }
                            UnityPlayer.this.resume();
                        }
                    };
                }
                this.a(runnable);
                return b3;
            }
            catch (InterruptedException ex) {
                final boolean b3 = b2;
                continue;
            }
            break;
        }
    }

    protected void startActivityIndicator() {
        this.a(this.t);
    }

    protected void stopActivityIndicator() {
        this.a(this.u);
    }

    protected void unloadGoogleVR() {
        this.v.d();
    }

    public void windowFocusChanged(final boolean b) {
        this.e.a(b);
        if (b && this.b != null) {
            this.reportSoftInputStr(null, 1, false);
        }
        this.b(new Runnable() {
            @Override
            public final void run() {
                UnityPlayer.this.nativeFocusChanged(b);
            }
        });
        this.a.a(b);
        this.f();
    }

    private final class a extends PhoneStateListener
    {
        public final void onCallStateChanged(final int n, final String s) {
            final UnityPlayer a = UnityPlayer.this;
            boolean b = true;
            if (n != 1) {
                b = false;
            }
            a.nativeMuteMasterAudio(b);
        }
    }

    enum b
    {
        a("PAUSE", 0),
        b("RESUME", 1),
        c("QUIT", 2),
        d("FOCUS_GAINED", 3),
        e("FOCUS_LOST", 4),
        f("NEXT_FRAME", 5);

        static {
            g = new b[] { b.a, b.b, b.c, b.d, b.e, b.f };
        }

        private b(final String s, final int n) {
        }
    }

    private final class c extends Thread
    {
        Handler a;
        boolean b;
        final /* synthetic */ UnityPlayer c;

        private c() {
            this.b = false;
        }

        private void a(final b b) {
            Message.obtain(this.a, 2269, (Object)b).sendToTarget();
        }

        public final void a() {
            this.a(UnityPlayer.b.c);
        }

        public final void a(final boolean b) {
            b b2;
            if (b) {
                b2 = UnityPlayer.b.d;
            }
            else {
                b2 = UnityPlayer.b.e;
            }
            this.a(b2);
        }

        public final void b() {
            this.a(UnityPlayer.b.b);
        }

        public final void c() {
            this.a(UnityPlayer.b.a);
        }

        @Override
        public final void run() {
            this.setName("UnityMain");
            Looper.prepare();
            this.a = new Handler((Handler.Callback)new Handler.Callback() {
                public final boolean handleMessage(final Message message) {
                    if (message.what != 2269) {
                        return false;
                    }
                    final b b = (b)message.obj;
                    Label_0159: {
                        if (b == UnityPlayer.b.c) {
                            Looper.myLooper().quit();
                        }
                        else if (b == UnityPlayer.b.b) {
                            UnityPlayer.c.this.b = true;
                        }
                        else {
                            c c;
                            if (b == UnityPlayer.b.a) {
                                c = UnityPlayer.c.this;
                                c.b = false;
                            }
                            else if (b == UnityPlayer.b.e) {
                                if (UnityPlayer.c.this.b) {
                                    break Label_0159;
                                }
                                c = UnityPlayer.c.this;
                            }
                            else {
                                if (b != UnityPlayer.b.f) {
                                    break Label_0159;
                                }
                                UnityPlayer.this.executeGLThreadJobs();
                                if (!UnityPlayer.this.isFinishing() && !UnityPlayer.this.nativeRender()) {
                                    UnityPlayer.this.c();
                                }
                                break Label_0159;
                            }
                            c.c.executeGLThreadJobs();
                        }
                    }
                    if (UnityPlayer.c.this.b) {
                        Message.obtain(UnityPlayer.c.this.a, 2269, (Object)UnityPlayer.b.f).sendToTarget();
                    }
                    return true;
                }
            });
            Looper.loop();
        }
    }

    private abstract class d implements Runnable
    {
        public abstract void a();

        @Override
        public final void run() {
            if (!UnityPlayer.this.isFinishing()) {
                this.a();
            }
        }
    }
}
